package com.zh.note.huawei.onehundred.IPv4地址转换成整数;

import java.util.Scanner;

/**
 * 100#101#1#5
 * 128#0#255#255
 */
public class Main {
    private static final String INVALID_IP = "invalid IP";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String input = scanner.nextLine();
            String[] ipParts = input.split("#");

            if (ipParts.length != 4) {
                System.out.println(INVALID_IP);
                continue;
            }
            boolean flag = false;
            StringBuilder binaryString = new StringBuilder();
            try {
                for (int i = 0; i < ipParts.length; i++) {
                    int num = Integer.parseInt(ipParts[i]);
                    if (i == 0 && (num < 0 || num > 128)) {
                        System.out.println(INVALID_IP);
                        flag = true;
                        break;
                    }
                    if (num < 0 || num > 255) {
                        System.out.println(INVALID_IP);
                        flag = true;
                        break;
                    }
                    //输出8位字符串
                    String s = Integer.toBinaryString(num);
                    String format = String.format("%8s", s);
                    String replace = format.replace(' ', '0');
                    binaryString.append(replace);

                }
                if (!flag) {
                    long res = Long.parseLong(binaryString.toString(), 2);
                    System.out.println(res);
                }


            } catch (NumberFormatException e) {
                System.out.println(INVALID_IP);
                continue;
            }


        }
    }
}

